<template>
  <div class="gift-qcode-page">
    <a-card>
      <a-table rowKey="id" :columns="columns" :pagination="pagination" :data-source="rows">
 <span slot="createtime" slot-scope="text">{{ formatDate(text) }}</span>
      </a-table>
    </a-card>

    <AddForm ref="AddForm" @handleSubmit="initData" />
  </div>
</template>
<script>
import * as Api from '@/api/gift'
import moment from 'moment'
export default {
  components: {
  },
  data() {
    return {
      columns: [
        {
          title: '用户姓名',
          dataIndex: 'nick_name',
        },
        {
          title: '联系方式',
          dataIndex: 'mobile',
        },
        {
          title: '兑换码',
          dataIndex: 'code',
        },
        {
          title: '兑换时间',
          dataIndex: 'createtime',
          scopedSlots: { customRender: 'createtime' },
        }
      ],
      rows: [],
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showTotal: (total) => `共 ${total} 条记录`,
        onChange: (page, pageSize) => {
          this.pagination.current = page
          this.pagination.pageSize = pageSize
          this.initData()
        },
      },
    }
  },

  mounted() {
    this.initData()
  },

  methods: {
    initData() {
      // 获取分类列表
      Api.exchangeLog({
        page: this.pagination.current,
      }).then((result) => {
        this.rows = result.data.list.data
		this.pagination.total = result.data.list.total
      })
    },


    // 时间格式化
    formatDate(time) {
      return moment(time * 1000).format('YYYY-MM-DD HH:mm')
    },
  },
}
</script>
